package dao.impl;

import dao.DeptDao;
import pojo.Dept;
import org.apache.ibatis.session.SqlSession;
import utils.MyBatisUtil;

import java.util.List;

public class DeptDaoImpl implements DeptDao {

    @Override
    public List<Dept> findAll(Dept dept) {
        return MyBatisUtil.getSession().getMapper(DeptDao.class).findAll(dept);
    }

    @Override
    public int deleteDeptById(int id) {
        // 拿到会话
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).deleteDeptById(id);
        // 提交事务
        session.commit();
        return result;
    }

    @Override
    public int addDept(Dept dept) {
        // 拿到会话
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).addDept(dept);
        // 提交事务
        session.commit();
        return result;
    }

    @Override
    public Dept findDeptById(int id) {
        return MyBatisUtil.getSession().getMapper(DeptDao.class).findDeptById(id);
    }

    @Override
    public int updateDept(Dept dept) {
        // 拿到会话
        SqlSession session = MyBatisUtil.getSession();
        int result = session.getMapper(DeptDao.class).updateDept(dept);
        // 提交事务
        session.commit();
        return result;
    }
}
